package com.extweb4j.core.model;

import com.extweb4j.core.kit.ExtKit;
import com.jfinal.plugin.activerecord.Page;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: .
 * @author: ZhaoWeiNan .
 * @createdTime: 2019/1/2 .
 * @version: 1.0 .
 */
public class ExtCompete extends CoreModel<ExtCompete> {

    private static final long serialVersionUID = 1L;

    private static final String SELECT_SQL = "SELECT InquiryNo, Title, TenderArea, NoticeType, PurchaseDept, Section, InquiryType, " +
            "BusinessType, Appraisal, PurchaserId, Purchaser, IsReview, AwardWay, TaxRate, SignUpTime, SignUpEndTime, StartTime, EndTime, " +
            "EndDay, OpenCondition, RequireFile," +
            " Remark, BiddingType, CanViewRank, CanViewHigthLow, StartPrice, AddPrice, IsChecked, Click, WinPostId, CreateTime, State ";

    private static final String FROM_SQL = " FROM Cm_Inquiry ";

    private static final String WHERE_SQL = " WHERE 1=1 ";

    public static ExtCompete dao = new ExtCompete();


    public Page<ExtCompete> pageXunJia(int page, int limit, String keywords) {

        List<Object> paras = new ArrayList<Object>();
        StringBuilder form = new StringBuilder();

        form.append(FROM_SQL);
        form.append(WHERE_SQL);
        form.append(" AND TenderArea = '002' ");

        if (StringUtils.isNotBlank(keywords)) {
            keywords = ExtKit.sqlFilterValidate(keywords);
            form.append(" AND (Title LIKE '%" + keywords + "%'");
        }
        form.append(" ORDER BY CreateTime ASC");
        return super.paginate(page, limit, SELECT_SQL, form.toString(), paras.toArray());
    }

    public Page<ExtCompete> pageJinJia(int page, int limit, String keywords) {

        List<Object> paras = new ArrayList<Object>();
        StringBuilder form = new StringBuilder();

        form.append(FROM_SQL);
        form.append(WHERE_SQL);
        form.append(" AND TenderArea = '003' ");

        if (StringUtils.isNotBlank(keywords)) {
            keywords = ExtKit.sqlFilterValidate(keywords);
            form.append(" AND (Title LIKE '%" + keywords + "%'");
        }
        form.append(" ORDER BY CreateTime ASC");
        return super.paginate(page, limit, SELECT_SQL, form.toString(), paras.toArray());
    }

    public Page<ExtCompete> pageTaiPan(int page, int limit, String keywords) {

        List<Object> paras = new ArrayList<Object>();
        StringBuilder form = new StringBuilder();

        form.append(FROM_SQL);
        form.append(WHERE_SQL);
        form.append(" AND TenderArea = '004' ");

        if (StringUtils.isNotBlank(keywords)) {
            keywords = ExtKit.sqlFilterValidate(keywords);
            form.append(" AND (Title LIKE '%" + keywords + "%'");
        }
        form.append(" ORDER BY CreateTime ASC");
        return super.paginate(page, limit, SELECT_SQL, form.toString(), paras.toArray());
    }



}
